import { BaseService } from './../../base/base.service';
import { Injectable } from '@nestjs/common';
import { UpdateWxAppConfigDto } from './dto/update-wx-app-config.dto';

@Injectable()
export class WxAppConfigService {
  constructor(private readonly baseService: BaseService){}

  async getOneByKey(configKey: string) {
    const config = await this.baseService.wxAppConfig.findUnique({
      where: {
        configKey
      }
    })
    return config
  }

  async updateWxAppConfig(id: string, dto: UpdateWxAppConfigDto) {
    const updateConfig = await this.baseService.wxAppConfig.update({
      where: {
        id
      },
      data: {
        peerUseCoin: dto.peerUseCoin,
        maxBuyCount: dto.maxBuyCount,
        maxBuyCountLock: dto.maxBuyCountLock,
        customerWxPic: dto.customerWxPic,
        customerWxStr: dto.customerWxStr
      }
    })
    return updateConfig
  }
}
